package com.knowledge.business.controller;


import java.util.Arrays;
import java.util.List;
import java.io.IOException;

import com.knowledge.common.annotation.Log;
import com.knowledge.common.core.controller.BaseController;
import com.knowledge.common.core.domain.AjaxResult;
import com.knowledge.common.enums.BusinessType;
import com.knowledge.common.utils.poi.ExcelUtil;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.knowledge.business.domain.TCp;
import com.knowledge.business.service.ITCpService;
import com.knowledge.common.core.page.TableDataInfo;

/**
 * 知识库产品名称Controller
 *
 * @author zhaoyk
 * @date 2025-09-28
 */
@RestController
@RequestMapping("/business/cp")
public class TCpController extends BaseController {
    @Autowired
    private ITCpService tCpService;

/**
 * 查询知识库产品名称列表
 */
//@RequiresPermissions("business:cp:list")
@GetMapping("/list")
    public TableDataInfo list(TCp tCp) {
        startPage();
        List<TCp> list = tCpService.selectTCpList(tCp);
        return getDataTable(list);
    }

    /**
     * 导出知识库产品名称列表
     */
    //@RequiresPermissions("business:cp:export")
    @Log(title = "知识库产品名称", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TCp tCp) {
        List<TCp> list = tCpService.selectTCpList(tCp);
        ExcelUtil<TCp> util = new ExcelUtil<TCp>(TCp. class);
        util.exportExcel(response, list, "知识库产品名称数据");
    }

    /**
     * 获取知识库产品名称详细信息
     */
    //@RequiresPermissions("business:cp:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(tCpService.getById(id));
    }

    /**
     * 新增知识库产品名称
     */
    //@RequiresPermissions("business:cp:add")
    @Log(title = "知识库产品名称", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TCp tCp) {
        return toAjax(tCpService.save(tCp));
    }

    /**
     * 修改知识库产品名称
     */
    //@RequiresPermissions("business:cp:edit")
    @Log(title = "知识库产品名称", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TCp tCp) {
        return toAjax(tCpService.updateById(tCp));
    }

    /**
     * 删除知识库产品名称
     */
    //@RequiresPermissions("business:cp:remove")
    @Log(title = "知识库产品名称", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(tCpService.removeByIds(Arrays.asList(ids)));
    }
}
